package com.fy.dishimei.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fy.dishimei.common.utils.PageUtils;
import com.fy.dishimei.domain.SysUser;
import com.fy.dishimei.domain.vo.UserAndSortVo;
import com.fy.dishimei.mapper.SysUserMapper;
import com.fy.dishimei.service.SysUserService;
import com.github.yulichang.query.MPJQueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author 13242
 * @description 针对表【sys_user(用户信息)】的数据库操作Service实现
 * @createDate 2023-11-27 16:56:35
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser>
        implements SysUserService {

    @Resource
    SysUserMapper sysUserMapper;


    @Override
    public PageUtils queryPage(Map<String, String> params) {
        boolean SUS_NAME = StringUtils.hasText(params.get("susName"));
        boolean SU_SEX = StringUtils.hasText(params.get("suSex"));
        boolean SU_AGEMin = StringUtils.hasText(params.get("suAgeMin"));
        boolean SU_AGEMax = StringUtils.hasText(params.get("suAgeMax"));
        int current = Integer.parseInt(params.get("page"));
        int size = Integer.parseInt(params.get("limit"));
        int sex = 0;
        if (SU_SEX){
             sex = Integer.parseInt(params.get("suSex"));
        }
        

        IPage<UserAndSortVo> page= sysUserMapper.selectJoinPage(new Page<>(current, size),
                UserAndSortVo.class,
                new MPJQueryWrapper<SysUser>()
                        .select("t.SU_CODE,t.SU_NAME,t.SU_SEX,t.SU_AGE,t1.SUS_NAME")
                        .leftJoin("sys_user_sort t1 on t1.SUS_CODE = t.SUS_CODE")
                        .like(SUS_NAME,"t1.SUS_NAME",params.get("susName"))
                        .eq(SU_SEX,"SU_SEX",sex)
                        .le(SU_AGEMax,"SU_AGE",params.get("suAgeMax"))
                        .ge(SU_AGEMin,"SU_AGE",params.get("suAgeMin"))

        );

        return new PageUtils(page);
    }
}




